#include "softwarestatus.h"

SoftwareStatus::SoftwareStatus(QWidget *parent)
{
    light = new QLabel(this);
    status = new QLabel(this);
    dateTime = new QLabel(this);
    timer = new QTimer(this);
    timer->start(1000);
    hLayout = new QHBoxLayout;

    hLayout->addWidget(light);
    hLayout->addWidget(status);
    hLayout->addWidget(dateTime);
    hLayout->setMargin(2);
    hLayout->addStretch();
    this->setLayout(hLayout);

    connect(this, SIGNAL(signal_status_changed(int)), this, SLOT(on_status_changed(int)));
    connect(timer, SIGNAL(timeout()), this, SLOT(slot_process_time_out()));

    ready();
}

void SoftwareStatus::ready()
{
    emit signal_status_changed(Normal);
}

void SoftwareStatus::on_status_changed(int status)
{
    switch(status)
    {
    case 0:
        this->status->setText("正常");
        light->setStyleSheet(m_green);
        break;
    case 1:
        this->status->setText("提示");
        light->setStyleSheet(m_blue);
        break;
    case 2:
        this->status->setText("警告");
        light->setStyleSheet(m_yellow);
        break;
    case 3:
        this->status->setText("错误");
        light->setStyleSheet(m_red);
    }
}

void SoftwareStatus::slot_process_time_out()
{
    dateTime->setText(QDateTime::currentDateTime()
                      .toString("yyyy年MM月dd日 hh时mm分ss秒 ddd"));
}
